package com.saturdaycoder.volumeman;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Button.*;

public class VolumeMan extends Activity {
	private Button buttonSwitch;
    /** Called when the activity is first created. */
	
	public static final String ACTION_SWITCH_PROFILE = "com.saturdaycoder.volumeman.ACTION_SWITCH_PROFILE";
	public static final String EXTRA_PROFILE_INDEX = "EXTRA_PROFILE_INDEX";
	
	public static final int PROFILE_INDEX_NORMAL = 0;
	public static final int PROFILE_INDEX_WORK = 1;
	public static final int PROFILE_INDEX_MEETING = 2;
	public static final int PROFILE_INDEX_HOME = 3;
	public static final int PROFILE_INDEX_SLEEP = 4;
	
	NotificationManager notManager;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        buttonSwitch = (Button)findViewById(R.id.buttonSwitch);
        
        String buttontext = Preference.getActive(VolumeMan.this)? "Disable": "Enable";
        buttonSwitch.setText(buttontext);
        
        notManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        
        buttonSwitch.setOnClickListener(new Button.OnClickListener() {
        	//@Override
        	public void onClick(View v) {
        		if (notManager == null) {
        			return;
        		} else {
        			Notification notification = new Notification(R.drawable.icon,
        					"Volume Man",
        	                System.currentTimeMillis());
        			
        			notification.flags |= Notification.FLAG_NO_CLEAR;
        			Intent it = new Intent(VolumeMan.this, ProfileSelectActivity.class);
        			PendingIntent pi = PendingIntent.getActivity(VolumeMan.this, 
        					0, it, 0);
        			notification.setLatestEventInfo(VolumeMan.this, 
        					getResources().getString(R.string.app_name), 
        					getResources().getString(R.string.instruction),
        					pi);
        			
        			if (!Preference.getActive(VolumeMan.this)) {
        				buttonSwitch.setClickable(false);
        				notManager.notify(1, notification);
        				Preference.setActive(VolumeMan.this, true);
        				buttonSwitch.setText("Disable");
        				buttonSwitch.setClickable(true);
        			} else {
        				buttonSwitch.setClickable(false);
        				notManager.cancel(1);
        				Preference.setActive(VolumeMan.this, false);
        				buttonSwitch.setText("Enable");
        				buttonSwitch.setClickable(true);
        			}
        		}
        		
        	}
        });
        

    }
}